{# Copyright 2014-2017 Siemens AG

   Copying and distribution of this file, with or without modification,
   are permitted in any medium without royalty provided the copyright notice and this notice are preserved.
   This file is offered as-is, without any warranty.
#}
{% macro radioGroup(id,options,select,action,separator) %}
  {% for key,disp in options %}
    {% if not loop.first %}{{ separator }}{% endif %}
    <input type="radio" name="{{ id }}" value="{{ key }}"
           {% if key == select %}selected="selected" {% endif %}{{ action }}>{{ disp }}
  {% endfor %}
{% endmacro %}

{% macro table(id, headers) %}
  <table border="1" id="{{ id }}">
    <thead>
      <tr>
        {% for header in headers %}
          <th>
            {{ '{{ header }}'| trans }}
          </th>
        {% endfor %}
      </tr>
    </thead>
  </table>
{% endmacro %}

{% macro select(name, options, id, selected, action, size) %}
  {% if selected is not defined %}
    {% set selected = -1 %}
  {% endif %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} multiple="multiple" size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      <option value="{{ key }}"{% if selected == key %} selected="selected"{% endif %}>
        {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}

{% macro selectsingle(name, options, id, selected, action, size) %}
  {% if selected is not defined %}
    {% set selected = -1 %}
  {% endif %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      <option value="{{ key }}"{% if selected == key %} selected="selected"{% endif %}>
        {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}

{% macro selectwitharray(name, options, id, selected, action, size) %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} multiple="multiple" size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      {% set selectedflag = false %}
      {% for num, license in selected %}
        {% if license == value %}
          {% set selectedflag = true %}
        {% endif %}
      {% endfor %}
      <option value="{{ key }}" {% if selectedflag %}selected="selected"{% endif %}>
      {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}
